﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;

namespace l1cs.server.clientpackets
{
    public class C_LoginToServerOK : ClientBasePacket
    {
        private const String _C_LOGIN_TO_SERVER_OK = "[C] C_LoginToServerOK";

        private static Logger _log = Logger.getLogger( typeof( C_LoginToServerOK ).FullName );

        public C_LoginToServerOK( byte[] decrypt, ClientThread client )
            : base( decrypt )
        {

            int type = readC();
            int button = readC();

            L1PcInstance pc = client.getActiveChar();

            if ( type == 255 )
            { // 全体チャット && Whisper
                if ( button == 95 || button == 127 )
                {
                    pc.setShowWorldChat( true ); // open
                    pc.setCanWhisper( true ); // open
                }
                else if ( button == 91 || button == 123 )
                {
                    pc.setShowWorldChat( true ); // open
                    pc.setCanWhisper( false ); // close
                }
                else if ( button == 94 || button == 126 )
                {
                    pc.setShowWorldChat( false ); // close
                    pc.setCanWhisper( true ); // open
                }
                else if ( button == 90 || button == 122 )
                {
                    pc.setShowWorldChat( false ); // close
                    pc.setCanWhisper( false ); // close
                }
            }
            else if ( type == 0 )
            { // 全体チャット
                if ( button == 0 )
                { // close
                    pc.setShowWorldChat( false );
                }
                else if ( button == 1 )
                { // open
                    pc.setShowWorldChat( true );
                }
            }
            else if ( type == 2 )
            { // Whisper
                if ( button == 0 )
                { // close
                    pc.setCanWhisper( false );
                }
                else if ( button == 1 )
                { // open
                    pc.setCanWhisper( true );
                }
            }
            else if ( type == 6 )
            { // 商売チャット
                if ( button == 0 )
                { // close
                    pc.setShowTradeChat( false );
                }
                else if ( button == 1 )
                { // open
                    pc.setShowTradeChat( true );
                }
            }
        }

        override
        public String getType()
        {
            return _C_LOGIN_TO_SERVER_OK;
        }
    }
}